//
//  MJ_ProjectDetailLayout.m
//  UEAssistant
//
//  Created by mac on 2018/1/10.
//  Copyright © 2018年 youyixinxi. All rights reserved.
//

#import "MJ_ProjectDetailLayout.h"
#import "UIImage+Color.h"
@implementation MJ_ProjectDetailLayout

- (instancetype)initWithModel:(MJProjectListModel *)model index:(NSInteger)index
{
    self = [super init];
    if (self) {
        if (index == 0) {
            LWTextStorage *projectTitle = [[LWTextStorage alloc] init];
            projectTitle.text = @"项目名称";
            projectTitle.frame = CGRectMake(18, 18, Screen_Width, 13);
            projectTitle.textColor = [UIColor colorWithHexString:@"#999999"];
            projectTitle.font = [UIFont systemFontOfSize:13];
            [self addStorage:projectTitle];
            
            LWTextStorage *projectContent = [[LWTextStorage alloc] init];
            projectContent.text = model.project_name;
            projectContent.frame = CGRectMake(18, projectTitle.bottom+12.0, Screen_Width-36, CGFLOAT_MAX);
            projectContent.textColor = [UIColor colorWithHexString:@"#333333"];
            projectContent.font = [UIFont systemFontOfSize:14];
            [self addStorage:projectContent];
            
        }else if(index == 1) {
            
            LWTextStorage *projectTitle = [[LWTextStorage alloc] init];
            projectTitle.text = @"项目经理";
            projectTitle.frame = CGRectMake(18, 18, Screen_Width, 13);
            projectTitle.textColor = [UIColor colorWithHexString:@"#999999"];
            projectTitle.font = [UIFont systemFontOfSize:13];
            [self addStorage:projectTitle];
            
            LWTextStorage *projectContent = [[LWTextStorage alloc] init];
            projectContent.text = model.vm_name;
            projectContent.frame = CGRectMake(18, projectTitle.bottom+12.0, Screen_Width-36, CGFLOAT_MAX);
            projectContent.textColor = [UIColor colorWithHexString:@"#333333"];
            projectContent.font = [UIFont systemFontOfSize:14];
            [self addStorage:projectContent];
            
        }else if (index == 2) {
            
            NSArray *title = @[@"语种",@"创建时间"];
            NSString *language = [NSString stringWithFormat:@"%@ - %@",model.sourcelangname,model.targetlangname];
            NSArray *contentArray = @[language,model.create_time];
            for (NSInteger i = 0; i < 2; ++ i) {
                LWTextStorage *projectTitle = [[LWTextStorage alloc] init];
                projectTitle.text = title[i];
                projectTitle.frame = CGRectMake(15, 12+24*i, Screen_Width, 13);
                projectTitle.textColor = [UIColor colorWithHexString:@"#666666"];
                projectTitle.font = [UIFont systemFontOfSize:13];
                [self addStorage:projectTitle];
                
                LWTextStorage *content = [[LWTextStorage alloc] init];
                content.text = contentArray[i];
                content.frame = CGRectMake(100, 12+24*i, Screen_Width, 13);
                content.textColor = [UIColor colorWithHexString:@"#666666"];
                content.font = [UIFont systemFontOfSize:13];
                [self addStorage:content];
            }
            
        }else if (index == 3) {
            
            LWTextStorage *projectContent = [[LWTextStorage alloc] init];
            projectContent.text = @"去重总字数";
            projectContent.frame = CGRectMake(15, 18, 100, CGFLOAT_MAX);
            projectContent.textColor = [UIColor colorWithHexString:@"#333333"];
            projectContent.font = [UIFont systemFontOfSize:14];
            [self addStorage:projectContent];
            
            LWTextStorage *rightWordcount = [[LWTextStorage alloc] init];
            rightWordcount.text = [NSString stringWithFormat:@"%@字",model.wordcount];
            rightWordcount.textAlignment = NSTextAlignmentRight;
            rightWordcount.frame = CGRectMake(Screen_Width-118, 18, 100, CGFLOAT_MAX);
            rightWordcount.textColor = [UIColor colorWithHexString:@"#333333"];
            rightWordcount.font = [UIFont systemFontOfSize:14];
            [self addStorage:rightWordcount];
            
            NSArray *title = @[@"非译去重",@"文件去重",@"机器翻译",@"团队语料",@"共享语料"];
            NSString *nowordCount = [NSString stringWithFormat:@"%ld字",model.no_wordcount];//非译去重
            NSString *fileWordCount = [NSString stringWithFormat:@"%ld字",model.dup_wordcount];//文件去重
            NSString *mtWordcount = [NSString stringWithFormat:@"%ld字",model.mt_wordcount];//机器翻译
            NSString *groupCount = [NSString stringWithFormat:@"%@字",model.selfpre_wordcount];//团队语料
            NSString *shareCount = [NSString stringWithFormat:@"%@字",model.sharepre_wordcount];//共享预料
            NSArray *wordCountArray = @[nowordCount,fileWordCount,mtWordcount,groupCount,shareCount];
            for (NSInteger i = 0; i < 5; ++ i) {
                
                LWTextStorage *projectTitle = [[LWTextStorage alloc] init];
                projectTitle.text = title[i];
                projectTitle.frame = CGRectMake(15, projectContent.bottom+12+24*i, Screen_Width, 13);
                projectTitle.textColor = [UIColor colorWithHexString:@"#666666"];
                projectTitle.font = [UIFont systemFontOfSize:13];
                [self addStorage:projectTitle];
                
                LWTextStorage *content = [[LWTextStorage alloc] init];
                content.text = wordCountArray[i];
                content.frame = CGRectMake(100, projectContent.bottom+12+24*i, Screen_Width, 13);
                content.textColor = [UIColor colorWithHexString:@"#666666"];
                content.font = [UIFont systemFontOfSize:13];
                [self addStorage:content];
            }
        }else{
            
            LWTextStorage *progress = [[LWTextStorage alloc] init];
            progress.text = @"项目进度";
            progress.frame = CGRectMake(15, 18, 100, CGFLOAT_MAX);
            progress.textColor = [UIColor colorWithHexString:@"#333333"];
            progress.font = [UIFont systemFontOfSize:14];
            [self addStorage:progress];
            
            NSArray *title = @[@"总进度",@"校    对",@"编    辑",@"翻    译"];
            CGFloat taskFinishPer = model.taskcount == 0 ? 0 : model.taskfinishcount/model.taskcount;//总进度
            CGFloat tranPer = model.tranfinishcount == 0 ? 0 : model.tranfinishcount/model.trancount;//翻译
            CGFloat proofPer = model.prooffinishcount == 0 ? 0 : model.prooffinishcount/model.proofcount;//校对
            CGFloat editPer = model.editfinishcount == 0 ? 0 : model.editfinishcount/model.editcount;//编辑
            NSString *total = [NSString stringWithFormat:@"%.0f%%",taskFinishPer*100];
            NSString *tran = [NSString stringWithFormat:@"%.0f%%",tranPer*100];
            NSString *proof = [NSString stringWithFormat:@"%.0f%%",proofPer*100];
            NSString *edit = [NSString stringWithFormat:@"%.0f%%",editPer*100];
            
            NSArray *array1 = @[total,proof,edit,tran];
            NSArray *colorArray = @[@"#7f7f7f",@"#52d09f",@"#2fbaf6",@"#f9975f"];
            for (NSInteger i = 0; i < 4; ++ i) {
                
                LWTextStorage *projectTitle = [[LWTextStorage alloc] init];
                projectTitle.text = title[i];
                projectTitle.frame = CGRectMake(15, progress.bottom+12+24*i, 60, 13);
                projectTitle.textColor = [UIColor colorWithHexString:@"#666666"];
                projectTitle.font = [UIFont systemFontOfSize:13];
                projectTitle.textAlignment = NSTextAlignmentLeft;
                [self addStorage:projectTitle];
                //百分比
                LWTextStorage *content = [[LWTextStorage alloc] init];
                content.text = array1[i];
                content.textAlignment = NSTextAlignmentLeft;
                content.frame = CGRectMake(Screen_Width-55, projectTitle.top, 40, 13);
                content.textColor = [UIColor colorWithHexString:@"#666666"];
                content.font = [UIFont systemFontOfSize:13];
                [self addStorage:content];
                //灰色条
                LWImageStorage *darkGrayProgress = [[LWImageStorage alloc] init];
                darkGrayProgress.frame = CGRectMake(projectTitle.right + 9.0, projectTitle.top + (content.height/4.0), content.left-projectTitle.right-18, content.height/2.0);
                darkGrayProgress.contents = [UIImage createImageWithColor:lineMainColor];
                darkGrayProgress.cornerRadius = content.height/4.0;
                darkGrayProgress.clipsToBounds = YES;
                [self addStorage:darkGrayProgress];
                
                CGFloat per = 0;
                switch (i) {
                    case 0:
                        per = taskFinishPer;
                        break;
                    case 1:
                        per = proofPer;
                        break;
                    case 2:
                        per = editPer;
                        break;
                    default:
                        per = tranPer;
                        break;
                }
                
                LWImageStorage *finishPerProgress = [[LWImageStorage alloc] init];
                finishPerProgress.frame = CGRectMake(darkGrayProgress.left, darkGrayProgress.top, darkGrayProgress.width*per, darkGrayProgress.height);
                finishPerProgress.cornerRadius = darkGrayProgress.height/2.0;
                finishPerProgress.contents = [UIImage createImageWithColor:[UIColor colorWithHexString:colorArray[i]]];
                finishPerProgress.clipsToBounds = YES;
                [self addStorage:finishPerProgress];
 
            }
        }

        self.cellHeight = [self suggestHeightWithBottomMargin:12];
    }
    return self;
}

@end
